package thread.unit1.exetend;
/**
 * 实现Runable接口实现多线程方式 例题1：
 * 卖票系统
 * 需求：
 * 例子：创建三个窗口卖票，总票数为100张.使用继承Thread类的方式
 *
 *   存在线程的安全问题，待解决。
 *   解决线程安全问题：thread/unit2/learncreate/ThreadSafeDemo1
 *
 */
public class ThreadP3 implements Runnable {

    private  int ticket = 100;

    public static void main(String[] args) {
        ThreadP3 threadP3 = new ThreadP3();
        Thread w1 = new Thread(threadP3,"窗口一");
        Thread w2 = new Thread(threadP3,"窗口二");
        Thread w3 = new Thread(threadP3,"窗口三");
        w1.start();
        w2.start();
        w3.start();
    }

    @Override
    public void run() {
        while (ticket>0){
            System.out.println(Thread.currentThread().getName()+"卖票，当前票号："+ticket);
            ticket--;
        }
    }
}

